package com.chaodev.base.service.impl;

import com.chaodev.base.dao.ActivityClockDao;
import com.chaodev.base.model.ActivityClock;
import com.chaodev.base.service.ActivityClockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ActivityClockServiceImpl implements ActivityClockService {

    @Autowired
    private ActivityClockDao activityClockDao;

    @Override
    public boolean addActivityClock(ActivityClock activityClock) {
        ActivityClock search = new ActivityClock();
        search.setActivityId(activityClock.getActivityId());
        search.setClockUserCode(activityClock.getClockUserCode());
        List<ActivityClock> list = activityClockDao.selectActivityClockList(search);
        if (list.size() == 0 ){
            activityClock.setClockType("sign in");
        }else if (list.size() == 1){
            activityClock.setClockType("sign out");
        }else {
            return false;
        }
        return activityClockDao.insertActivityClock(activityClock) != 0;
    }

    @Override
    public List<ActivityClock> getActivityClockList(ActivityClock activityClock) {
        return activityClockDao.selectActivityClockList(activityClock);
    }
}
